// // client.js
const { createSocket } = require("dgram");

const client = createSocket("udp4");

client.on("error", (err) => {
  console.log(`错误信息:\n${err.stack}`);
  client.close();
});

client.on("listening", () => {
  const address = client.address();
  console.log(`发送信息地址: ${address.address}:${address.port}`);
});

client.on("message", (msg, rinfo) => {
  console.log(`来自 ${rinfo.address}:${rinfo.port}的信息: ${msg}`);
});

// let ip = "192.168.10.50"

let ip = "localhost";

let message = "你好";

client.send(message, 9000, (error) => {
  client.close();
});
